function varargout = gui_filter(varargin)
% GUI_FILTER MATLAB code for gui_filter.fig
%      GUI_FILTER, by itself, creates a new GUI_FILTER or raises the existing
%      singleton*.
%
%      H = GUI_FILTER returns the handle to a new GUI_FILTER or the handle to
%      the existing singleton*.
%
%      GUI_FILTER('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUI_FILTER.M with the given input arguments.
%
%      GUI_FILTER('Property','Value',...) creates a new GUI_FILTER or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before gui_filter_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to gui_filter_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help gui_filter

% Last Modified by GUIDE v2.5 17-Dec-2013 10:20:45

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @gui_filter_OpeningFcn, ...
                   'gui_OutputFcn',  @gui_filter_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before gui_filter is made visible.
function gui_filter_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to gui_filter (see VARARGIN)

handles.input = varargin{1};
handles.hough = handles.input;
handles.bild = varargin{2};
img2 = handles.bild;
img2(handles.input > 0) = 255;
axes(handles.axes1);
imshow(img2);

% Choose default command line output for gui_filter
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes gui_filter wait for user response (see UIRESUME)
 uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = gui_filter_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.eyes;
close(handles.figure1);

function maxL_Callback(hObject, eventdata, handles)
% hObject    handle to maxL (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of maxL as text
%        str2double(get(hObject,'String')) returns contents of maxL as a double



function minL_Callback(hObject, eventdata, handles)
% hObject    handle to minL (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of minL as text
%        str2double(get(hObject,'String')) returns contents of minL as a double



function maxS_Callback(hObject, eventdata, handles)
% hObject    handle to maxS (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of maxS as text
%        str2double(get(hObject,'String')) returns contents of maxS as a double


% --- Executes on button press in filter.
function filter_Callback(hObject, eventdata, handles)
% hObject    handle to filter (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

maxL = str2double(get(handles.maxL, 'String'));
minL = str2double(get(handles.minL, 'String'));
maxS = str2double(get(handles.maxS, 'String'));
maxDiff = str2double(get(handles.maxDiff, 'String'));

ret = filterCircles(handles.input, minL, maxL, maxS, maxDiff);
img2 = handles.bild;
img2(ret > 0) = 255;
[rows, cols] = size(ret);
imshow(img2);
hold on
 for x=1:rows
          viscircles([ret(x,1), ret(x,2)],ret(x,5));
          viscircles([ret(x,3), ret(x,4)],ret(x,5));
 end
handles.eyes = ret;
axes(handles.axes1);
guidata(hObject, handles);

% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
uiresume(handles.figure1);



function maxDiff_Callback(hObject, eventdata, handles)
% hObject    handle to maxDiff (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of maxDiff as text
%        str2double(get(hObject,'String')) returns contents of maxDiff as a double
